package New;

public class BinarySearch {
    public static int binarySearch(Integer [] srcArray,int des){
//       定义初始大小，最大索引
        int start = 0;
        int end = srcArray.length-1;
        //确保不会出现重复查找，越界
        while (start <=end){
            //计算出中间索引值
            int middle = (end +start)>>>1;//防止溢出
            if(des == srcArray[middle]){
                return middle;
                //判断下限
            }else if (des<srcArray[middle]){
                end = middle-1;
                //判断上限
            }else {
                start = middle+1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(binarySearch(new Integer[]{1,2, 6, 8, 9, 11, 13, 17}, 11));

    }
}
